package com.sojson.config.qps.sentinel.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sojson.config.qps.sentinel.util.SentinelUtil;

/**
 * 自定义Sentinel限流异常处理
 * 
 * @author liu
 * @date 2021-08-25
 */
@Configuration
public class CustomUrlBlockHandler implements BlockExceptionHandler {

    /**
     * 限流的时候触发
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
        // 输出数据
        SentinelUtil.out(request, response, e);
    }

}